<?php
namespace app\forum\controller;
use app\forum\controller\SiteController;
/**
 * 用户首页
 */

class UserHomeController extends SiteController {

	/**
     * 初始化
     */
	public function init(){
		$userId = request('get.user_id');
    	if(empty($userId)){
    		$this->error404();
    	}
    	//获取用户信息
    	$this->userInfo = target('User')->getInfo($userId);
    	if(empty($this->userInfo)){
    		$this->error404();
    	}
    	$where = array();
    	$where['C.user_id'] = $userId;
		$threadCount = target('Thread')->countList($where);
		$where = array();
    	$where['B.user_id'] = $userId;
		$replyCount = target('Reply')->countList($where);
		//用户菜单
		$this->menuList = array(
			array('name'=>'主题','sub_name'=>$threadCount,'url'=>url('thread',array('user_id'=>$userId))),
			array('name'=>'回复','sub_name'=>$replyCount,'url'=>url('reply',array('user_id'=>$userId))),
			);
		$this->userId = $userId;

	}

	/**
     * 主页
     */
    public function index(){
    	//主题
    	$where = array();
    	$where['C.user_id'] = $this->userId;
		$threadList = target('Thread')->loadList($where,5);
		//回复
		$where = array();
    	$where['A.user_id'] = $this->userId;
		$replyList = target('Reply')->loadThreadList($where,5);

    	$this->assign('threadList',$threadList);
    	$this->assign('replyList',$replyList);
        $this->siteDisplay();
    }

    /**
     * 主题
     */
    public function thread(){
    	$where = array();
    	$where['C.user_id'] = $this->userId;
		$pageList = target('Thread')->page(20)->loadList($where);
		$this->pager = target('Thread')->pager;
		//URL参数
        $pageMaps = array();
        $pageMaps['user_id'] = $this->userId;
        //获取分页
        $page = $this->getPageShow($pageMaps);
    	$this->assign('pageList', $pageList);
    	$this->assign('page', $page);
        $this->siteDisplay();
    }

    /**
     * 回复
     */
    public function reply(){
    	$where = array();
    	$where['A.user_id'] = $this->userId;
		$pageList = target('Reply')->page(20)->loadThreadList($where);
		$this->pager = target('Reply')->pager;
		//URL参数
        $pageMaps = array();
        $pageMaps['user_id'] = $this->userId;
        //获取分页
        $page = $this->getPageShow($pageMaps);
    	$this->assign('pageList', $pageList);
    	$this->assign('page', $page);
        $this->siteDisplay();
    }

    
}